<template>
    <view>
        <view class="container">
					<view class="top-nav flex-box flex-between fs28 col5 tc">
						<navigator url="#" hover-class="none">
							<image class="icon" src="/static/icon/msg-nav1.png" mode="aspectFit"></image>
							<view>站内消息</view>
						</navigator>
						<navigator url="#" hover-class="none">
							<image class="icon" src="/static/icon/msg-nav2.png" mode="aspectFit"></image>
							<view>签约提醒</view>
						</navigator>
						<navigator url="#" hover-class="none">
							<image class="icon" src="/static/icon/msg-nav3.png" mode="aspectFit"></image>
							<view>新房动态</view>
						</navigator>
						<navigator url="#" hover-class="none">
							<image class="icon" src="/static/icon/msg-nav4.png" mode="aspectFit"></image>
							<view>每日推送</view>
						</navigator>
					</view>
					
            <view class="df ac item" @tap="gotomsg" :data-classify="item.classify" v-for="(item, index) in msg_data"  >
                <image :src="item.avatar" :lazy-load="true" class="userpic" mode="aspectFill"></image>

                <view class="flex-grow-1">
                    <view class="fs32 pb10">{{ item.name }}</view>
                    <view class="fs28 colc single-line">{{ item.msg }}</view>
                </view>
            </view>
            <template v-if="loadingList.data.length > 0">
                <view class="df ac item" @tap="gotochat" :data-session_id="item.id" v-for="(item, index) in loadingList.data"  >
                    <image :src="user_id!=item.receive_user_id?item.receiveuser.avatar:item.senduser.avatar" lazy-load class="userpic" mode="aspectFill"></image>

                    <view class="flex-grow-1">
                        <view class="fs32 pb10">{{user_id!=item.receive_user_id?item.receiveuser.nickname:item.senduser.nickname }}</view>
                        <view class="fs28 colc single-line">{{ item.newmsg.content_text2 }}</view>
                    </view>

                    <view v-if="item.unread_num > 0" class="hint-num">
                        <text>{{ item.unread_num }}</text>
                    </view>
                </view>
            </template>
        </view>
    </view>
</template>

<script>
const app = getApp();

const functions = require('../../../utils/functions.js');

export default {
    data() {
        return {
			loadingList: {
			  total: 0,
			  current_page: 0,
			  last_page: 1,
			  data: []
			},
			user_id:0,
            msg_data: [],
			
        };
    },
    onShow: function () {
		var that =this;
        this.initData();
		if(app.globalData.chat_config.ortherdata){
			
			uni.$on('session_list_callback',function(data){
				console.log(data)
				that.session_list(data);
			})
			this.user_id=app.globalData.chat_config.ortherdata.user_info.user_id
			this.session_list();
		}
    },
    onReachBottom: function () {
		if (this.loadingList.current_page < this.loadingList.last_page && this.loadingList.current_page!=0) {
		  app.ws_send({
			type: 'sessionlist',
			session_time: app.globalData.chat_config.session_time,
			session_id: app.globalData.chat_config.session_id,
		  });
		}
	},
    methods: {
        gotomsg(e) {
            var classify = Number(e.currentTarget.dataset.classify);

            switch (classify) {
                case 1:
                    uni.navigateTo({
                        url: '/pages/chat/system_msg/system_msg'
                    });
                    break;

                case 2:
                    uni.navigateTo({
                        url: '/pages/member/everyday_push/everyday_push'
                    });
                    break;

                case 3:
                    uni.navigateTo({
                        url: '/pages/member/point_detail/point_detail'
                    });
                    break;

                case 4:
                    uni.switchTab({
                        url: '/pages/home/information/information'
                    });
                    break;

                default:
                    break;
            }
        },

		gotochat(e){
		    var session_id=e.currentTarget.dataset.session_id;
		    wx.navigateTo({
		      url: '/pages/chat/chat/chat?session_id='+session_id,
		    })
		  },
		session_list(){
			if(app.globalData.chat_config.session_list){
			  this.loadingList=app.globalData.chat_config.session_list
			}
		},

        // 获取系统消息
        initData() {
            var that = this;
            functions.getAjaxData('/api/xiluhouse/Chat/msg_data', {}, function (res) {
                that.msg_data=res.data
            });
        }
    }
};
</script>
<style>
@import url('@/static/css/old_project.css');
.item {
    padding: 20rpx 30rpx;
    border-bottom: 1px solid #f6f7fa;
}
.userpic {
    width: 100rpx;
    height: 100rpx;
    margin-right: 20rpx;
    border-radius: 50%;
}
.hint-num {
    padding-left: 30rpx;
}
.hint-num text {
    position: relative;
    top: auto;
    right: auto;
    min-width: 32rpx;
}

.top-nav {
		padding: 0 10rpx;
		margin: 0 0 30rpx;

		.icon {
			margin: 0 auto 25rpx;
			display: block;
			width: 85rpx;
			height: 85rpx;
		}
	}
</style>
